import { requestClient } from '#/api/request';

export namespace vendorAPI {
  export interface RowType {
    searchValue: null;
    createBy: string;
    createTime: Date;
    updateBy: string;
    updateTime: Date;
    remark: string;
    params: any;
    vendorId: number;
    vendorCode: string;
    vendorName: string;
    vendorNick: string;
    vendorEn: null | string;
    vendorDes: null | string;
    vendorLogo: null | string;
    vendorLevel: string;
    vendorScore: number;
    address: null | string;
    website: null | string;
    email: null | string;
    tel: null | string;
    contact1: null | string;
    contact1Tel: null | string;
    contact1Email: null | string;
    contact2: null | string;
    contact2Tel: null | string;
    contact2Email: null | string;
    creditCode: null | string;
    enableFlag: string;
    attr1: null;
    attr2: null;
    attr3: number;
    attr4: number;
  }
  export interface vendor {
    code: number;
    msg: string;
    rows: [];
    total: number;
  }
}

export const getVendors = (params?: {
  itemTypeId?: number;
  page?: number;
  pageSize?: number;
}) => {
  return requestClient.get<vendorAPI.vendor>('/mes/md/vendor/list', {
    params,
  });
};

// 删除供应商
export const deleteVendor = (id: string) => {
  return requestClient.delete<vendorAPI.vendor>(`/mes/md/vendor/${id}`);
};

// 新增供应商
export const addVendor = (data: vendorAPI.RowType) => {
  return requestClient.post<vendorAPI.vendor>('mes/md/vendor', data);
};

// 更新供应商
export const updateVendor = (data: vendorAPI.RowType) => {
  return requestClient.put<vendorAPI.vendor>('/mes/md/vendor', data);
};
